package cn.xianshu.feign.client;

import cn.xianshu.domain.Login;
import cn.xianshu.dto.LoginAndMealDto;
import cn.xianshu.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 降级类
 */
@Component
@Slf4j
public class loginFeignClientFallbackFactory implements FallbackFactory<LoginFeignClient> {


    @Override
    public LoginFeignClient create(Throwable throwable) {

        return new LoginFeignClient() {
            /**
             * 降级方法
             * @param login
             * @return
             */
            @Override
            public AjaxResult save(Login login) {
                log.error("保存Login到认证中心异常:{}" , throwable.getMessage());
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("保存Login到认证中心异常!");
            }

            @Override
            public AjaxResult saveLoginAndMeal(LoginAndMealDto loginAndMealDto) {
                log.error("保存Login到认证中心异常:{}" , throwable.getMessage());
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("保存Login到认证中心异常!");
            }
        };
    }
}
